package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.entity.dto.DishDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {
    @Select("select count(*) from save where category_id=#{id}")
    int findCount(Long id);


    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    //把主键封装给形参
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void save(DishDto dishDto);


    List<Dish> findByName(@Param("name") String name);

    @Select("select * from dish where id = #{id}")
    Dish findById(Long dishId);

    void updateById(DishDto dishDto);


    List<DishDto> findByCategoryId(@Param("categoryId") Long categoryId, @Param("status") Integer status);


    void updateStatus(@Param("status") Integer status, @Param("ids") List<Long> ids);

    int findStatusCount(@Param("ids") List<Long> ids);

    void deleteByIds(@Param("ids") List<Long> ids);
}
